package com.likou.second_challenge;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class q128 {

    public int longestConsecutive(int[] nums) {

        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }

        int ans = 0;
        for (int num : nums) {
            if (!set.contains(num - 1)) {
                int temp = num;
                int l = 1;
                while (set.contains(temp + 1)) {
                    l++;
                    temp++;
                }

                ans = Math.max(ans, l);
            }
        }

        return ans;
    }

}
